package com.zoo.diannaopeijian.controller.shipment;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.ShipmentTarget;
import com.zoo.diannaopeijian.service.ShipmentTargetService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 出货对象控制器
 */
@Controller
@RequestMapping("/shipmentTarget")
public class ShipmentTargetController extends BaseController {
    @Resource
    private ShipmentTargetService shipmentTargetService;

    @GetMapping(value = "/pages/{pageName}")
    public String pageRoute(@PathVariable String pageName) {
        return "shipment/shipmentTarget/" + pageName;
    }

//    @RequestMapping("/exportChannelManaPage")
//    public String exportChannelManaPageRoute() {
//        return "export/exportChannel/exportChannelManaPage";
//    }
//
//    @RequestMapping("/exportChannelAddPage")
//    public String exportChannelAddPageRoute()  {
//        return "export/exportChannel/exportChannelAddPage";
//    }
//
//    @RequestMapping("/exportChannelUpdatePage")
//    public String exportChannelUpdatePageRoute()  {
//        return "export/exportChannel/exportChannelUpdatePage";
//    }

    @GetMapping("/list")
    public ResponseEntity<Map<String, Object>> shipmentTargetListGet(Page page) {
        return ResponseEntity.ok(buildPageResult(shipmentTargetService.getAllShipmentTarget(page)));
    }

    @GetMapping("/")
    public ResponseEntity<List<ShipmentTarget>> shipmentTargetGet() {
        return ResponseEntity.ok(shipmentTargetService.getAllShipmentTarget(null));
    }

    @PostMapping("/")
    public ResponseEntity<String> shipmentTargetPost(ShipmentTarget shipmentTarget) {
        return ResponseEntity.ok(shipmentTargetService.addShipmentTarget(shipmentTarget) ? success : fail);
    }

    @PutMapping("/")
    public ResponseEntity<String> shipmentTargetPut(ShipmentTarget shipmentTarget) {
        return ResponseEntity.ok(shipmentTargetService.updateShipmentTarget(shipmentTarget) ? success : fail);
    }

    @DeleteMapping("/{shipmentTargetId}")
    public ResponseEntity<String> shipmentTargetDelete(@PathVariable Integer shipmentTargetId) {
        return ResponseEntity.ok(shipmentTargetService.deleteShipmentTargetById(shipmentTargetId) ? success : fail);
    }
}
